home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CTOOLS10.ARJ / LIST.H < prev    next >
C/C++ Source or Header  |  1991-12-31  |  3KB  |  111 lines

  1. /****************************************************************************
  2. *
  3. *                    Copyright (C) 1991 Kendall Bennett.
  4. *                            All rights reserved.
  5. *
  6. * Filename:        $RCSfile: list.h $
  7. * Version:        $Revision: 1.7 $
  8. *
  9. * Language:        ANSI C
  10. * Environment:    any
  11. *
  12. * Description:    Header file for linked list routines.
  13. *
  14. * $Id: list.h 1.7 91/12/31 19:41:16 kjb Exp $
  15. *
  16. * Revision History:
  17. * -----------------
  18. *
  19. * $Log:    list.h $
  20. * Revision 1.7  91/12/31  19:41:16  kjb
  21. * Modified include files directories.
  22. * Revision 1.6  91/09/27  03:11:04  kjb
  23. * Added compatibility with C++.
  24. * Revision 1.5  91/09/26  10:07:42  kjb
  25. * Took out extern references
  26. * Revision 1.4  91/09/01  17:18:24  ROOT_DOS
  27. * Changed prototype for lst_deletenext().
  28. * Revision 1.3  91/09/01  15:15:46  ROOT_DOS
  29. * Changed search for include files to include current directory
  30. * Added function lst_kill().
  31. * Revision 1.2  91/08/22  11:06:50  ROOT_DOS
  32. * Header file for corresponding revision of source module
  33. * Revision 1.1  91/08/21  14:11:39  ROOT_DOS
  34. * Initial revision
  35. ****************************************************************************/
  36.  
  37. #ifndef    __LIST_H
  38. #define    __LIST_H
  39.  
  40. #ifndef    __DEBUG_H
  41. #include "debug.h"
  42. #endif
  43.  
  44. /*---------------------- Macros and type definitions ----------------------*/
  45.  
  46. typedef struct LST_BUCKET {
  47.     struct LST_BUCKET    *next;
  48.     } LST_BUCKET;
  49.  
  50. typedef struct {
  51.     int            count;            /* Number of elements currently in list    */
  52.     LST_BUCKET    *head;            /* Pointer to head element of list        */
  53.     LST_BUCKET    *z;                /* Pointer to last node of list            */
  54.     LST_BUCKET    hz[2];            /* Space for head and z nodes            */
  55.     } LIST;
  56.  
  57. /* Return a pointer to the user space given the address of the header of
  58.  * a node.
  59.  */
  60.  
  61. #define    LST_USERSPACE(h)    ((void*)((LST_BUCKET*)(h) + 1))
  62.  
  63. /* Return a pointer to the header of a node, given the address of the
  64.  * user space.
  65.  */
  66.  
  67. #define    LST_HEADER(n)        ((LST_BUCKET*)(n) - 1)
  68.  
  69. /* Return a pointer to the user space of the list's head node. This user
  70.  * space does not actually exist, but it is useful to be able to address
  71.  * it to enable insertion at the start of the list.
  72.  */
  73.  
  74. #define    LST_HEAD(l)            LST_USERSPACE((l)->head)
  75.  
  76. /* Determine if a list is empty
  77.  */
  78.  
  79. #define    LST_EMPTY(l)        ((l)->count == 0)
  80.  
  81. /*-------------------------- Function Prototypes --------------------------*/
  82.  
  83. #ifdef __cplusplus
  84. extern "C" {
  85. #endif
  86.  
  87. void *lst_newnode(int size);
  88. void lst_freenode(void *node);
  89. LIST *lst_init(void);
  90. void lst_kill(LIST *l,void (*freeNode)());
  91. void lst_insertafter(LIST *l,void *node,void *after);
  92. void *lst_deletenext(LIST *l,void *node);
  93. void *lst_first(LIST *l);
  94. void *lst_next(void *prev);
  95. void lst_mergesort(LIST *l,int (*cmp_func)());
  96.  
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100.  
  101. #endif
  102.